package dk.au.cs.bdsi.mail.activities;

import dk.au.cs.bdsi.core.representation.Identifier;
import dk.au.cs.bdsi.core.representation.ServiceUri;
import dk.au.cs.bdsi.mail.domain.Mail;
import dk.au.cs.bdsi.mail.repositories.MailRepository;
import dk.au.cs.bdsi.mail.representation.MailRepresentation;

/**
 * Retrieves a {@link Mail} by its identification (as extracted from the supplied
 * {@link ServiceUri}) and returns a {@link MailRepresentation} of it. 
 */
public class ReadMailActivity {
	public MailRepresentation retrieve(ServiceUri mailUri) {
		Identifier id = mailUri.getId();
		Mail m = MailRepository.current().get(id);
		if (m == null) throw new NoSuchMailException();
		
		return MailRepresentation.createResponseRepresentation(m, mailUri);
	}
}
